using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Library.Utilities;
using NCS.Library;

namespace NCS.Module.CMS.Web.HomePage
{
    public partial class EventList : CMSWebControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            this.link_toeventlist.NavigateUrl = BuildUrlbyEvent();

            this.LoadData();
        }

        private void LoadData() {
            this.rpt_1.DataSource = NCS.Module.CMS.Library.Events.EventController.GetAllByNum(5);
            this.rpt_1.ItemDataBound += new RepeaterItemEventHandler(rpt_1_ItemDataBound);
            this.rpt_1.DataBind();
        }

        void rpt_1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DataRowView row = (DataRowView)e.Item.DataItem;
            if (row != null) {
                Image img = (Image)e.Item.FindControl("event_img");
                string src = ConvertUtility.ToString(row["Event_Avatar"]);
                if (!string.IsNullOrEmpty(src) && System.IO.File.Exists(Server.MapPath(src)))
                {
                    img.ImageUrl = src;
                }
                else
                {
                    img.ImageUrl = "/images/noimage.png";
                }

                HyperLink link = (HyperLink)e.Item.FindControl("event_link");

                link.Text = ConvertUtility.ToString(row["Event_Name"]);
                link.NavigateUrl = this.BuildUrlbyEvent(ConvertUtility.ToInt32(row["Event_ID"]));
            }
        }
    }
}